﻿using System.Linq.Expressions;

namespace Mg.ExpressionParser.Parser
{
    class ConstantExpressionParser : BaseExpressionParser<ConstantExpression>
    {
        protected override SqlPack Where(ConstantExpression expression, SqlPack sqlPack)
        {
            sqlPack.AddDbParameter(expression.Value);
            return sqlPack;
        }

        protected override SqlPack In(ConstantExpression expression, SqlPack sqlPack)
        {
            if (expression.Type.Name == "String")
            {
                sqlPack.Sql.AppendFormat("'{0}',", expression.Value);
            }
            else
            {
                sqlPack.Sql.AppendFormat("{0},", expression.Value);
            }
            return sqlPack;
        }
    }
}
